package leetcode.剑指offer;

import java.util.HashMap;
import java.util.Map;

public class 复杂链表的复制35 {
    public Node copyRandomList(Node head) {
        if(head == null)
            return head;
        Map<Node,Node> map = new HashMap<>();
        for(Node cur = head;cur!= null;cur = cur.next){
            map.put(cur,new Node(cur.val));
        }
        for (Node cur = head;cur !=null;cur = cur.next){
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);

        }
        return map.get(head);
    }
}
